<!--
 * @Author: Chili
 * @Date: 2019-07-08 15:25:58
 * @LastEditors: Chili
 * @LastEditTime: 2019-08-02 14:36:19
 * @Description: 需求梳理
 -->
<!-- 
    1.已巡检的点位，再次扫码，仅提示（wc）
    2.消息像这种提示未完成状态,已完成，应该跳转到归档记录  （gsy）
    3.app巡检，所有能看到巡检任务的用户都可以做巡检 （hiny）
 -->

<template>
    <div class="page checkApply-page" id="newCheckApply_{{getNewId}}" data-page="newCheckApply" style="z-index: 2;">
        <div class="link-page-nav">
            <a href="#" class="link" @click="$root.backToTab()">
                <i class="iconfont icon-zuo"></i>
            </a>
        </div>
        <div class="link-page-top" style="padding-bottom: 17px;">
            <div class="link-page-title">日常巡检</div>
            <a href="#" class="link" @click="getHistoryData">
                <i class="iconfont icon-APPicon_lishi" style="font-size:23px"></i>
            </a>
        </div>
        <div class="link-page-tab">
            <div class="checkApply-tab" id="checkApply-tab_{{getNewId}}">
                <a href="#" class="checkApply-link"  @click="updateView(0)">待领取</a>
                <a href="#" class="checkApply-link"  @click="updateView(1)">执行中</a>
                <a href="#" class="checkApply-link"  @click="updateView(2)">已完成</a>
            </div>
            <div class="opacity0" id="device-identification-opacity"></div>
        </div>
        <div data-infinite-distance="50" class="page-content infinite-scroll-content ptr-content"
            @ptr:refresh="refreshCurrentList">
            <div class="ptr-preloader" style="top: -10px;">
                <div class="preloader color-multi"></div>
                <div class="ptr-arrow"></div>
            </div>
            <div class="list media-list">
                <ul id="check-content_{{getNewId}}"></ul>
            </div>
        </div>
        <!-- 执行中 -->
        <div class="more-task-btn device-identification" id="device-identification_{{getNewId}}" @click="scanning">
            <i class="iconfont icon-weibiaoti--2"></i>
        </div>
    </div>
</template>

<script>
    return {
        mounted() {
            var self = this;
            self.view_status = self.$route.params.tabId*1;
            self.date = self.$route.params.date;
        },
        data: function () {
            return {
                pageName: "newCheckApply",
                orgId: userInfor.org.id,
                // dateValus:['全部时间','今天','三天','七天','一个月','三个月'],
                view_status: self.view_status ? self.view_status : 2, //2待领取 3执行中 4已完成 5已过期
                status: 2, //0:所有 1：未发布 2：已发布(待领取) 3：巡检中 4：巡检完成 5：已过期 6：已重新巡检
                fbsId: 0, //消防建筑物id
                areaId: 0,
                nfcDialog: null, // nfc扫描弹框
                check_point_array: [], //多选时候保存点位id的数组
                rejectedId: null, //驳回任务id
                visualCode: '',
                selectContent: '', //搜索内容
                startTime: self.date ? moment(self.date).format('YYYY-MM-DD 23:59:59') : moment().subtract(1,
                    "days").format('YYYY-MM-DD 23:59:59'), //开始时间
                endTime: self.date ? moment(self.date).add(1, "days").format('YYYY-MM-DD 23:59:59') : moment()
                    .format('YYYY-MM-DD 23:59:59'), //结束时间
                isInfinite: false,
                isOpenMore: false,
                selectOptionIndex: '0',
                getNewId: (new Date()).getTime()
            }
        },
        methods: {
            backToRefresh:function(){
                var self = this;
                if(2 !== self.status){
                    self.updateView(self.view_status);
                }
            },
            getHistoryData: function () {
                app.router.navigate("/inspectRecords/");
            },
            // backToHome: function () {
            //     // if (app.view.get("#todayInspect")) {
            //     //     app.view.get("#todayInspect").router.currentPageEl.f7Component.showInspectCount();
            //     // }
            //     app.methods.backToTab();
            // },
            refreshCurrentList: function (e, done) { //刷新功能
                var self = this;
                var $ = self.$$;
                if (done && e) {
                    setTimeout(function () {
                        self.listIndex = 0;
                        self.updateView(self.view_status);
                        done();
                    }, 1000);
                }
            },
            updateView: function (status) { //初始化方法和切换方法
                if (getClickEnabel()) {
                    var self = this;
                    var $ = self.$$;
                    self.status = status;
                    self.view_status = status;
                    //选择框变色
                    $("#checkApply-tab_"+self.getNewId+" .checkApply-link").removeClass('active').eq((status)).addClass('active');
                    $("#checkApply-page_"+self.getNewId+" .tab-link-highlight").css("left", (status == 0 ? 1 : status * 33.3333) +
                        "%");
                    //$("#checkApplyList").empty();
                    // $("#checkApplyList_preloader").show();
                    if (status == 0) { //待领取
                        // $(".quiting-task").show();
                        // $(".quit-maoretask-btn").show();
                        // $(".quit-task-btn").hide();
                        $("#device-identification_"+self.getNewId).hide();
                    } else if (status == 1) { //执行中
                        // $(".quiting-task").hide();
                        $("#device-identification_"+self.getNewId).show();
                    } else { //已完成
                        // $(".quiting-task").hide();
                        $("#device-identification_"+self.getNewId).hide();
                    }
                    //获取巡检列表
                    self.getTaskListInfo();
                }
            },
            //根据联网单位id获取巡检任务列表
            getTaskListInfo: function () {
                let self = this;
                let selectOrgId = userInfor.organizationIds;
                let IS_OFFLINE_MODULE = native.getDataByKey("IS_OFFLINE_MODULE");//离线维保
                if(IS_OFFLINE_MODULE == "1"){
                    selectOrgId = native.getDataByKey("OFFLINE_SELECT_ORGID")
                }
                $("#device-identification-opacity").show()
                $("#check-content_"+self.getNewId).empty();
                Dao.getInspectTaskInfoByStatus({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    orgIds: selectOrgId,
                    status: self.status,
                    account: userInfor.accountName,
                    taskId: ""
                }, function (data) {
                    $("#device-identification-opacity").hide()
                    if (data && data.length > 0) {
                        //待领取列表
                        if (self.status == 0) {
                            for (var i = 0; i < data.length; i++) {
                                //遍历任务id
                                var pointList = data[i].inspectPointResult;
                                var dataPointList = "";
                                for (var j = 0; j < pointList.length; j++) {
                                    if (j == pointList.length - 1) {
                                        dataPointList += pointList[j].id;
                                    } else {
                                        dataPointList += pointList[j].id + ",";
                                    }
                                }
                                $("#check-content_"+self.getNewId).append(`
                                    <li class="checkApply-li">
                                        <div class="checkApply-task-top">
                                            <a href="/waitApply/` + data[i].id + `/` + data[i].orgId + `/" >
                                                <div>
                                                    <div class="checkApply-task-name">
                                                        <div>` + common.transNullundefinedToline(data[i].taskName) + `</div> 
                                                        <div class="isout" id="isOutTime`+`_`+self.getNewId+`_` + data[i].id + `">即将过期</div> 
                                                    </div>
                                                    <div class="checkApply-task-totle" id="totalTask_`+self.getNewId+`_` + data[i].id +
                                        `">共有巡检点位` + data[i].totalPointNum + `个</div>
                                                    <div class="checkApply-task-totle">剩余待领取` + data[i].unRunPointNum + `个</div>
                                                    <div class="checkApply-task-totle" id="taskOrgName_`+self.getNewId+`_` + data[i].id +
                                        `" style="display:none;">` + common.transNullundefinedToline(data[i]
                                            .orgName) + `</div>
                                                </div>
                                            </a>
                                        </div>
                                        <div class="checkApply-task-bottom" id="task-time-`+self.getNewId+`_` + data[i].id + `" style="min-height:35px;height:initial; padding: 5px 15px;">
                                            <div  id="taskOutTime_`+self.getNewId+`_` + data[i].id + `"></div>
                                            <div  style="overflow:hidden">
                                                <div id="inspect-takeAll-btn_`+self.getNewId+`_` + data[i].id + `" data-id="` +
                                        dataPointList + `" data-taskId="` + data[i].id + `" style="float: right;text-align: center;color: #fff; padding: 5px 15px;border-radius: 15px;
                                        margin-bottom:  10px;background: rgba(224, 119, 98, 0.5);
                                        min-width:90px;box-sizing:border-box
                                        "></div>
                                            </div>
                                        </div>
                                       
                                    </li>
                                `);

                                //是否快要过期
                                var now = moment().format("YYYY-MM-DD HH:mm:ss");
                                var a = moment(data[i].expiredTime);
                                var b = moment(now); //当前时间
                                var c = a.diff(b, 'hours');

                                //到期时间
                                var tempTime = moment.duration(a - b);
                                var h = tempTime.hours();
                                var m = tempTime.minutes();
                                var s = tempTime.seconds();
                                $("#taskOutTime_"+self.getNewId+"_" + data[i].id).html(`
                                    <div>
                                        <span class="time" style="color:#FFF">` + ((h < 10) ? ("0" + h) : h) + `</span>
                                        <span class="dot">:</span>    
                                        <span class="time" style="color:#FFF">` + ((m < 10) ? ("0" + m) : m) + `</span>
                                        <span class="dot">:</span>
                                        <span class="time" style="color:#FFF">` + ((s < 10) ? ("0" + s) : s) + `</span>
                                        <span class="dot" style="margin:0;margin-left: 2px;">后过期</span>
                                    </div>
                                `);

                                //到期时间样式
                                if (c <= 0) {
                                    $("#task-time-"+self.getNewId+"_" + data[i].id).css("background",
                                        "rgba(224, 119, 98, 0.2)");
                                    $("#inspect-takeAll-btn_"+self.getNewId+"_" + data[i].id).html("立即领取").css("background-color",
                                        "#E07762");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .time").css("background-color",
                                        "rgba(224, 119, 98, 0.5)");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .dot").css("color",
                                        "rgba(224, 119, 98, 0.6)");
                                    $("#isOutTime_"+self.getNewId+"_" + data[i].id).show();
                                } else {
                                    $("#task-time-"+self.getNewId+"_" + data[i].id).css("background", "rgba(36,113,202,0.2)");
                                    $("#inspect-takeAll-btn_"+self.getNewId+"_" + data[i].id).html("领取").css("background-color",
                                        "#2471CA");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .time").css("background-color",
                                        "rgba(36, 113, 202, 0.5)");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .dot").css("color",
                                        "rgba(36, 113, 202, 0.6)");
                                    $("#isOutTime_"+self.getNewId+"_" + data[i].id).hide();
                                }

                                $("#totalTask_"+self.getNewId+"_" + data[i].id).show();
                                $("#taskOrgName_"+self.getNewId+"_" + data[i].id).show();

                                //领取按钮
                                jQuery("#inspect-takeAll-btn_"+self.getNewId+"_" + data[i].id).off().on("click", {'data': ''}, function (event) {

                                    tipsDialog("您确认领取<br/>这条巡检任务吗？", "确定", "不了，再想想",
                                        function () {
                                            var pointIds = jQuery(event.currentTarget)
                                                .attr("data-id");
                                            var taskId = jQuery(event.currentTarget)
                                                .attr("data-taskId");
                                            self.takeTask(taskId, pointIds);
                                            layer.closeAll();
                                        }, staticPath +
                                        "img/hidden/check-multi-task.png");
                                    
                                    event.stopPropagation(); //停止事件冒泡
                                });
                                
                            }
                        }
                        //执行中
                        else if (self.status == 1) {
                            for (var i = 0; i < data.length; i++) {
                                $("#check-content_"+self.getNewId).append(`
                            <li class="checkApply-li accordion-item">
                                <a href="#" class="item-content item-link" style="border-bottom: 1px solid rgba(225, 225, 225, 0.5);">
                                    <div class="item-inner">
                                        <div class="item-title" style="font-size: 17px;color: #333;margin-bottom: 8px;font-weight: bold;white-space:normal">` +
                                    common.transNullundefinedToline(data[i].taskName) + `</div>
                                        <div class="item-footer" style="font-size: 14px;margin-bottom: 2px;">剩余` +
                                    data[i].runningPointNum + `个点位</div>
                                        <div class="item-footer" style="font-size: 14px;" id="taskOrgName_`+self.getNewId+`_` + data[i]
                                    .id + `" style="display:none;">` + data[i].orgName + `</div>
                                    </div>
                                </a>
                                <div class="accordion-item-content" id="task-list-`+self.getNewId+`_` + data[i].id + `"></div>
                                <div class="perform-con" id="taskOutTime_`+self.getNewId+`_` + data[i].id + `"></div>
                            </li>`);

                                if (userInfor.isMuilUnitUser != 0) {
                                    $("#taskOrgName_"+self.getNewId+"_" + data[i].id).show();
                                }

                                //是否快要过期
                                var now = moment().format("YYYY-MM-DD HH:mm:ss");
                                var a = moment(data[i].expiredTime);
                                var b = moment(now); //当前时间
                                var c = a.diff(b, 'hours');

                                //到期时间
                                var tempTime = moment.duration(a - b);
                                var h = tempTime.hours();
                                var m = tempTime.minutes();
                                var s = tempTime.seconds();
                                $("#taskOutTime_"+self.getNewId+"_" + data[i].id).html(`
                                    <div>
                                        <span class="time" style="color:#FFF">` + ((h < 10) ? ("0" + h) : h) + `</span>
                                        <span class="dot">:</span>    
                                        <span class="time" style="color:#FFF">` + ((m < 10) ? ("0" + m) : m) + `</span>
                                        <span class="dot">:</span>
                                        <span class="time" style="color:#FFF">` + ((s < 10) ? ("0" + s) : s) + `</span>
                                        <span class="dot" style="margin-left: 2px;">后过期</span>
                                    </div>
                                `);

                                //到期时间样式
                                if (c <= 0) {
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id).css("background",
                                        "rgba(224, 119, 98, 0.2)");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .time").css("background-color",
                                        "rgba(224, 119, 98, 0.5)");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .dot").css("color",
                                        "rgba(224, 119, 98, 0.6)");
                                } else {
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id).css("background",
                                    "rgba(36,113,202,0.2)");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .time").css("background-color",
                                        "rgba(36, 113, 202, 0.5)");
                                    $("#taskOutTime_"+self.getNewId+"_" + data[i].id + " .dot").css("color",
                                        "rgba(36, 113, 202, 0.6)");
                                }

                                //展开后
                                var pointList = data[i].inspectPointResult; //领取的点位
                                for (var j = 0; j < pointList.length; j++) {
                                    var image = staticPath + "img/emptyImg/default_check.png";
                                    if (pointList[j].picUrl && pointList[j].picUrl.split(',').length > 0) {
                                        image = pointList[j].picUrl + '?imageView2/0/w/120';
                                    }
                                    $("#task-list-"+self.getNewId+"_" + data[i].id).append(`
                                    <a href="#" class="item-content" id="checkApplying_`+self.getNewId+`_` + pointList[j].id + `-` +
                                        data[i].id + `" data-id="` + pointList[j].visualCode + `" >
                                        <div class="item-inner">
                                            <div class="item-title" >
                                                <div class="item-header" style="height:initial;overflow:hidden">` + common.transNullundefinedToline(pointList[
                                            j].name) + `</div>
                                                <span>` + common.transNullundefinedToline(pointList[j].address) + `</span>
                                            </div>
                                            <div class="item-after">由` + common.transNullundefinedToline(pointList[j]
                                            .inspectPointAccount) + `巡检</div>
                                        </div>
                                        <div class="task-pic">
                                            <img src="` + image + `" id="doing-dropDowm-img-`+self.getNewId+`_` + pointList[j].id + `">
                                        </div>
                                    </a>
                                    `);
                                    jQuery("#doing-dropDowm-img-"+self.getNewId+`_` + pointList[j].id).off("click").on("click", {
                                        'data': pointList[j].picUrl.split(',')
                                    },function (e) {
                                        openAndShowBigImage(e.data.data,0);
                                        e.stopPropagation();
                                    });

                                    jQuery("#checkApplying_"+self.getNewId+"_" + pointList[j].id + "-" + data[i].id).off('click').on('click', {
                                        'taskId': data[i].id
                                    }, function (e) {
                                        if (jQuery(e.target).hasClass("checkApply-address")) {
                                            return;
                                        }
                                        var visualCode = jQuery(e.currentTarget).attr("data-id");
                                        var taskId = e.data.taskId;
                                        //判断是否有特殊字符
                                        var isHave = visualCode.indexOf("#");
                                        var newCode = "";
                                        if (isHave == 0) {
                                            newCode = visualCode.substring(1);
                                        } else {
                                            newCode = visualCode;
                                        }
                                        app.router.navigate('/checkCompletedNew/' + isHave + "/" + newCode + '/' + taskId + '/');
                                        e.stopPropagation();
                                    });
                                }
                            }
                        } 
                        //已完成
                        else { 
                            for (var i = 0; i < data.length; i++) {
                                $("#check-content_"+self.getNewId).append(`
                            <li  class="checkApply-li accordion-item">
                                <a href="#" class="item-content item-link" style="border-bottom: 1px solid rgba(225, 225, 225, 0.5);">
                                    <div class="item-inner">
                                        <div class="item-title" style="font-size: 17px;color: #333;margin-bottom: 8px;font-weight: bold;white-space:normal">` +
                                    common.transNullundefinedToline(data[i].taskName) + `</div>
                                        <div class="item-footer" style="font-size: 14px;margin-bottom: 2px;">共有巡检点位` +
                                    data[i].totalPointNum + `个</div>
                                        <div class="item-footer" style="font-size: 14px;margin-bottom: 2px;">已完成点位` +
                                    data[i].finishedPointNum + `个点位</div>
                                        <div class="item-footer" style="font-size: 14px;" id="taskOrgName` + data[i]
                                    .id + `" style="display:none;">` + data[i].orgName + `</div>
                                    </div>
                                </a>
                                <div class="accordion-item-content" id="task-list-`+self.getNewId+`_` + data[i].id + `"></div>
                            </li>`);
                                if (userInfor.isMuilUnitUser != 0) {
                                    $("#taskOrgName_"+self.getNewId+"_" + data[i].id).show();
                                } else {
                                    $("#taskOrgName_"+self.getNewId+"_" + data[i].id).hide();
                                }
                                //展开
                                var pointList = data[i].inspectPointResult; //领取的点位
                                for (var j = 0; j < pointList.length; j++) {
                                    var image = staticPath + "img/emptyImg/default_check.png";
                                    if (pointList[j].picUrl && pointList[j].picUrl.split(',').length > 0) {
                                        image = pointList[j].picUrl + '?imageView2/0/w/120';
                                    }
                                    $("#task-list-"+self.getNewId+"_" + data[i].id).append(`
                                        <a href="#" class="item-content" id="checkApply_`+self.getNewId+`_` + pointList[j].id + `-` + data[i]
                                            .id + `" data-id="` + pointList[j].visualCode + `">
                                            <div class="item-inner">
                                                <div class="item-title">
                                                    <div class="item-header" style="height:initial;overflow:hidden">
                                                        <div class="name">` + common.transNullundefinedToline(pointList[j]
                                                .name) + `</div>
                                                        <div class="isOk" id="isOk-`+self.getNewId+`_` + pointList[j].id + `">` + common
                                            .transNullundefinedToline(pointList[j].pointResultDesc) + `</div>
                                                    </div>
                                                    <span>` + common.transNullundefinedToline(pointList[j].address) + `</span>
                                                </div>
                                                <div class="item-after">
                                                    <span style="color: #2471CA;">` + moment(pointList[j].finishTime)
                                            .format("MM-DD HH:mm") + `&nbsp;&nbsp;</span>
                                                    <span style="color: #2471CA;">由` + common.transNullundefinedToline(
                                                pointList[j].inspectPointAccount) + `巡检完成</span>
                                                </div>
                                            </div>
                                            <div class="task-pic">
                                                <img src="` + image + `" id="doing-dropDowm-img-`+self.getNewId+`_` + pointList[j].id + `">
                                            </div>
                                        </a>
                                    `);

                                    if (pointList[j].pointResultDesc == "合格") {
                                        $("#isOk-"+self.getNewId+"_" + pointList[j].id).css("background", "#69BA71");
                                    } else if (pointList[j].pointResultDesc == "全部不合格") {
                                        $("#isOk-"+self.getNewId+"_" + pointList[j].id).css("background", "#F02020");
                                    } else if (pointList[j].pointResultDesc == "未巡检") {
                                        $("#isOk-"+self.getNewId+"_" + pointList[j].id).css("background", "#9A9A9A");
                                    } else {
                                        $("#isOk-"+self.getNewId+"_" + pointList[j].id).css("background", "#F8B728");
                                    }

                                    jQuery("#doing-dropDowm-img-"+self.getNewId+`_` + pointList[j].id).off("click").on("click", {
                                        'data': pointList[j].picUrl.split(',')
                                    },function (e) {
                                        openAndShowBigImage(e.data.data,0);
                                        e.stopPropagation();
                                    });
                                    
                                    jQuery("#checkApply_"+self.getNewId+"_" + pointList[j].id + "-" + data[i].id).off('click').on('click', {
                                        'taskId': data[i].id
                                    }, function (e) {
                                        if (jQuery(e.target).hasClass("checkApply-address")) {
                                            return;
                                        }
                                        var visualCode = jQuery(e.currentTarget).attr("data-id");
                                        var taskId = e.data.taskId;
                                        //判断是否有特殊字符
                                        var isHave = visualCode.indexOf("#");
                                        var newCode = "";
                                        if (isHave == 0) {
                                            newCode = visualCode.substring(1);
                                        } else {
                                            newCode = visualCode;
                                        }
                                        app.router.navigate('/checkCompletedNew/' + isHave + "/" + newCode + '/' + taskId + '/');
                                        e.stopPropagation();
                                    });
                                }
                            }
                        }
                    } else {
                        $("#check-content_"+self.getNewId).append(`<div class="no-data-img"><img src="` + listNoDataPic() +`"/></div>`);
                    }
                });
            },
            //领取任务
            takeTask: function (taskId, pointIds) {
                let self = this;
                Dao.takeTaskNew({
                    userName: userInfor.accountName,
                    deviceId: appKeyObj.deviceId,
                    taskId: taskId,
                    pointIds: pointIds,
                    account: userInfor.accountName
                }, function (data) {
                    if (data.status == 200) {
                        app.methods.showToastCenter('领取巡检任务成功！');
                    } else if (data.status == 203) {
                        common.loading(0);
                        app.methods.showToastCenter('部分点位已领取或已完成,领取巡检任务失败！');
                    } else {
                        common.loading(0);
                        app.methods.showToastCenter('领取巡检任务失败！');
                    }
                    self.getTaskListInfo(0);
                });
            },
            //原生扫一扫
            scanning: function () {
                native.scanQrCode();
            },
            //提报隐患
            createTrouble: function () {
                app.router.navigate("/createTrouble/-1/-1/-1/");
            },
            //NFC
            nFCrecognition: function () {
                var isSupportNFC = native.startNFC();
                var nfc = isSupportNFC.split(",");
                if (nfc[0] == 0) {
                    app.dialog.create({
                        title: '提示',
                        text: '当前设备暂不支持NFC扫描功能',
                        buttons: [{
                            text: '确定',
                            click: function () {}
                        }],
                        verticalButtons: true,
                    }).open();
                } else {
                    this.nfcDialog = app.dialog.create({
                        title: '提示',
                        text: nfc[1] == 0 ? '请先在设置中启用NFC功能' : '请将设备靠近巡检点位标签',
                        buttons: [{
                            text: nfc[1] == 0 ? '确定' : '取消',
                            onClick: function () {
                                if (nfc[1] == 0) {

                                } else {
                                    // 取消扫面二维码，关闭NFC扫描资源
                                    native.stopNFC();
                                }
                            }
                        }],
                        verticalButtons: true,
                    });
                    this.nfcDialog.open();
                }
            },
        },
        on: {
            pageInit: function (e, page) {
                var self = this;
                var $ = self.$;
                if (self.date) {
                    var date = moment(self.date);

                    var index = Math.floor((moment().toDate() - date.toDate()) / (1000 * 60 * 60 * 24));
                    if (index > 30) {
                        self.selectOptionIndex = '0';
                        // $("#date_select").removeClass('search-select');
                    } else {
                        self.selectOptionIndex = index;
                        // $("#date_select").addClass('search-select');
                    }
                    self.startTime = moment(self.date).format('YYYY-MM-DD 00:00:00');
                    self.endTime = moment(self.date).format('YYYY-MM-DD 23:59:59');
                    self.updateView(self.view_status);
                } else {
                    self.updateView(self.view_status ? self.view_status : 0);
                }
            },
            pageBeforeOut: function (e, page) {
                //离开页面前  销毁nfc
                native.stopNFC();
            }
        },
    }
</script>